{% extends 'layout/project.html' %}
{% load static %}
{% block title %}
    项目中心
{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/btn/style.css' %}">
    <style>


        .project a {
            text-decoration: none;
            font-size: 18px;
            color: gray;
            margin-top: 10px;
        }

        .error-msg {
            color: red;
            position: absolute;
            font-size: 5px;
        }

        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .panel-body > .item > .info a {
            text-decoration: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 18px;
        }


        .color-radio label {
            margin-left: 0;
            padding-left: 0;
        }

        .color-radio input[type="radio"] {
            display: none;
        }

        .color-radio input[type="radio"] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        .color-radio input[type="radio"]:checked + .cycle {
            border: 2px solid black;
        }


    </style>
{% endblock %}

{% block content %}
    <!--按钮开始-->
    <div class="container-fluid">

        <button class="btn btn-6" data-toggle="modal" data-target="#addModel">
            添加项目
        </button>
        <!--模态框-->
        <div class="modal fade" id="addModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title text-center" id="myModalLabel">添加项目</h4>
                    </div>
                    <form id="addForm" novalidate>
                        {% csrf_token %}
                        <div class="modal-body">
                            {% for field in form %}
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                {{ field }}
                                <span class="error_msg" style="color: red;"></span>
                            {% endfor %}

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <input type="button" id="btnProject" class="btn btn-primary" value="保存">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--按钮end-->

    <!--面板开始-->
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="fa fa-star"></span>
                星标项目
            </h3>
        </div>
        <div class="panel-body">
            {% for item in project_lists.star %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.value.id %}" class="title"
                       style="background-color: {{ item.value.get_color_display }};">
                        {{ item.value.name }}
                    </a>
                    <div class="info">
                        <div>
                            <!--星标链接-->
                            <a href="{% url 'un_star' project_type=item.type project_id=item.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #f0ad4e"></i>
                            </a>
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true">{{ item.value.project_num }}</i>
                            <span></span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>

    <div class="panel panel-success">
        <div class="panel-heading"><i class="fa fa-list" aria-hidden="true"></i>我创建的项目</div>
        <div class="panel-body">

            {% for item in project_lists.my %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.value.id %}" class="title"
                       style="background-color: {{ item.value.get_color_display }};">
                        {{ item.value.name }}

                    </a>
                    <div class="info">
                        <div>
                            <a href="{% url 'add_star' project_type=item.type project_id=item.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true">{{ item.value.project_num }}</i>
                            <span></span>
                        </div>
                    </div>
                </div>
            {% endfor %}

        </div>
    </div>


    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="fa fa-handshake-o"></span>
                我加入的项目
            </h3>
        </div>
        <div class="panel-body">
            {% for item in project_lists.join %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.value.id %}" class="title"
                       style="background-color: {{ item.value.get_color_display }};">
                        {{ item.value.name }}
                    </a>
                    <div class="info">
                        <div>
                            <a href="{% url 'add_star' project_type=item.type project_id=item.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true">{{ item.value.project_num }}</i>
                            <span></span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>
    <!--面板end-->
{% endblock %}

{% block js %}
    <script>
        $(function () {
            addProject();
        })

        function addProject() {
            $('#btnProject').click(function () {
                $('.error_msg').empty();
                $.ajax({
                    url: "{% url 'project' %}",
                    type: "POSt",
                    data: $('#addForm').serialize(),
                    dataType: "JSON",
                    success: function (ret) {
                        if (ret.status) {
                            location.href =
                            {% url 'project' %}
                        } else {
                            $.each(ret.msg, function (key, value) {
                                $('#id_' + key).next().text(value[0])
                            })
                        }
                    }
                })

            })
        }
    </script>
{% endblock %}


